{extend name='Public:content'}
{block name="button"}
<div id="toolbar" class="row">
    <div class="col-sm-12 m-b-xs">
        <button type="button" class="btn-sm btn-info" onClick="$.Oa.reload()">
            <span class="fa fa-refresh" aria-hidden="true"></span>刷新
        </button>
        <button id="btn_add" type="button" class="btn-sm btn-success" title="添加菜单" onclick="menu_index.add()">
            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>添加菜单
        </button>
    </div>
</div>
{/block}
{block name="content"}
<form id="menu_form" action='{:url("$classuri/index")}' method="post">
    <input type="hidden" value="resort" name="action"/>
    <table id="menu_table" class="table table-bordered">
        <thead>
        <tr>
            <th class='text-center' width="10%">
                <button class="btn btn-info btn-sm" type="button" onclick="menu_index.sort()"> 确认排序</button>
            </th>
            <th class='text-center'>图标</th>
            <th class='text-center' width="5%">全部展开</th>
            <th>菜单名称</th>
            <th>菜单链接</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {foreach $list as $key=>$vo}
        <tr data-pid="{$vo.pid}">
            <td width="10%">
                <input name="_{$vo.id}" value="{$vo.sort}" class="list-sort-input"/>
            </td>
            <td class='text-center'>
                <i style="font-size:18px;" class="{$vo.icon}"></i>
            </td>
            <td class='text-center'>
                {eq name="vo.pid" value="0"}
                    <div class="th-inner"><a onclick="menu_index.toggle(this);" data-id="{$vo.id}" class="btn btn-info btn-xs btn-toggle" style="display: inline-block; width: 24px; height: 22px;"><i class="fa fa-chevron-down"></i></a></div>
                {/eq}
            </td>
            <td>{$vo.spl}{$vo.title}</td>
            <td>{$vo.url}</td>
            <td>
                {if $vo.status eq 2}
                <span class="label label-danger">已禁用</span>
                {elseif $vo.status eq 1}
                <span class="label label-primary">使用中</span>
                {/if}
            </td>
            <td>
                {if auth("$classuri/edit")}
                <a onclick="menu_index.edit('{$vo.id}')" class="btn btn-white btn-xs">编辑</a>
                {/if}
                {if $vo.status eq 1 and auth("$classuri/status")}
                <a onclick="$.Oa.status(this,'string')" data-url='{:url("$classuri/status")}' data-id="{$vo.ids}" data-value="2" class="btn btn-white btn-xs">禁用</a>
                {elseif auth("$classuri/status")}
                <a onclick="$.Oa.status(this,'string')" data-url='{:url("$classuri/status")}' data-id="{$vo.ids}" data-value="1" class="btn btn-white btn-xs">启用</a>
                {/if}
                {if auth("$classuri/del")}
                <a onClick="$.Oa.delete(this,false,false)" data-href='{:url("$classuri/del")}' data-id="{$vo.ids}" class="btn btn-outline btn-xs btn-danger" title="删除" >删除</a>
                {/if}
            </td>
        </tr>
        {/foreach}
        </tbody>
    </table>
</form>
{/block}
{block name="script"}
<script type="text/javascript">
    window.menu_index = {
        //定义工具栏
        //toolbar: "#menu_index_toolbar",
        add: function(){ //添加
            parent.layer.open({
                type: 2,
                title: '{$title} > 添加',
                shadeClose: false,
                shade: 0.8,
                maxmin: true, //开启最大化最小化按钮
                area: ['960px', '650px'],
                content: '{:url("$classuri/add")}?iframe='+window.name,
                yes: function (index, layero){},
                end: function (){}
            });
        },
        edit: function(id){ //编辑
            parent.layer.open({
                type: 2,
                title: '{$title} > 编辑',
                shadeClose: false,
                shade: 0.8,
                maxmin: true, //开启最大化最小化按钮
                area: ['960px', '650px'],
                content: '{:url("$classuri/edit")}?id='+id+'&iframe='+window.name,
                yes: function (index, layero){},
                end: function (){}
            });
        },
        sort: function(){ //排序
            $.Oa.doHform('#menu_form',false,false,function(ret){
                $.Oa.reload();
            });
        },
        toggle: function(_this){ //隐藏显示
            var pid = $(_this).attr('data-id');
            var tmp_i =  $(_this).children('i');
            if(tmp_i.hasClass('fa-chevron-down')){
                tmp_i.removeClass('fa-chevron-down').addClass('fa-chevron-right');
                //隐藏子菜单
                $(_this).parents('table').find('tr').each(function (i,ob) {
                    if($(ob).attr('data-pid') == pid){
                        $(ob).hide();
                    }
                })
            }else{
                tmp_i.removeClass('fa-chevron-right').addClass('fa-chevron-down');
                //展示子菜单
                $(_this).parents('table').find('tr').each(function (i,ob) {
                    if($(ob).attr('data-pid') == pid){
                        $(ob).show();
                    }
                })
            }

        }
    }
</script>
{/block}